package com.example.testdemo.scenes.menu;

import org.andengine.engine.camera.Camera;
import org.andengine.entity.scene.menu.MenuScene;
import org.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener;
import org.andengine.entity.scene.menu.item.IMenuItem;
import org.andengine.entity.scene.menu.item.SpriteMenuItem;

import android.opengl.GLES20;

import com.example.testdemo.TankGameActivity;
import com.example.testdemo.manager.ResourcesManager;
import com.example.testdemo.manager.ScenesManager;
import com.example.testdemo.resources.MenuInGameResources;

public class MenuInGameScene extends BaseMenu implements
        IOnMenuItemClickListener {

	protected static final int MENU_RESET = 0;
	protected static final int MENU_QUIT = 1;
	protected static final int MENU_TAG = 1030;

	private TankGameActivity mActivity;
	private MenuInGameResources mMenuResources;

	private int mFatherScene;

	public MenuInGameScene(Camera camera, int fatherScene) {
		super(camera);
		mFatherScene = fatherScene;
		mMenuResources = (MenuInGameResources) ResourcesManager.getInstance()
		        .getResources(ScenesManager.MENU_IN_GAME);
	}

	@Override
	public void createScene(TankGameActivity activity) {
		mActivity = activity;

		final SpriteMenuItem resetMenuItem = new SpriteMenuItem(MENU_RESET,
		        mMenuResources.mMenuResetTextureRegion,
		        activity.getVertexBufferObjectManager());
		resetMenuItem.setBlendFunction(GLES20.GL_SRC_ALPHA,
		        GLES20.GL_ONE_MINUS_SRC_ALPHA);
		addMenuItem(resetMenuItem);

		final SpriteMenuItem quitMenuItem = new SpriteMenuItem(MENU_QUIT,
		        mMenuResources.mMenuQuitTextureRegion,
		        activity.getVertexBufferObjectManager());
		quitMenuItem.setBlendFunction(GLES20.GL_SRC_ALPHA,
		        GLES20.GL_ONE_MINUS_SRC_ALPHA);
		addMenuItem(quitMenuItem);

		buildAnimations();

		setBackgroundEnabled(false);

		setOnMenuItemClickListener(this);
	}

	@Override
	public void populateScene() {

	}

	@Override
	public boolean onMenuItemClicked(MenuScene pMenuScene, IMenuItem pMenuItem,
	        float pMenuItemLocalX, float pMenuItemLocalY) {
		switch (pMenuItem.getID()) {
		case MENU_RESET:
			ScenesManager.getInstance().getScene(mFatherScene).resetScene();
			return true;
		case MENU_QUIT:
			mActivity.finish();
			return true;
		default:
			return false;
		}
	}

	@Override
	public void onBackKeyPressed() {
	}

	@Override
	public void disposeScene() {
	}

}
